#include"mq_connection.hpp"

int main()
{
    //1、实例化异步线程池
    bitmq::AsyncWord::ptr awp=std::make_shared<bitmq::AsyncWord>();
    //2、实例化连接对象
    bitmq::Connection::ptr conn=std::make_shared<bitmq::Connection>("127.0.0.1",8888,awp);
    //3、通过连接创建信道
    bitmq::Channel::ptr channel=conn->createChannel();
    //4、通过信道，声明所需
    //  1、声明一个交换机exchange1  广播类型
    google::protobuf::Map<std::string, std::string> map;
    channel->declareExchange("exchange1",bitmq::ExchageType::TOPIC,true,false,map);
    //  2、声明一个queue1  --  queue1
    channel->declareQueue("queue1",true,false,false,map);
    //  3、声明一个queue2  --  news.music.#
    channel->declareQueue("queue2",true,false,false,map);
    //  4、将exchange1  与  queue1绑定起来
    channel->basicBind("exchange1","queue1","queue1");
    //  5、将exchange2  与  queue2绑定起来
    channel->basicBind("exchange1","queue2","news.music.#");
    //5、循环向队列里发送消息
    for(int i=0;i<10;i++)
    {
        // bitmq::BasicProperties bp;
        // bp.set_id(bitmq::UUIDHelper::uuid());
        // bp.set_delivery_mode(bitmq::DeliveryMode::DURABLE);
        // bp.set_routing_key("queue1");
        // channel->basicPubish("exchange1",&bp,"Hello World"+std::to_string(i));
       // std::cout<< i << "发布消息了 " << i << std::endl;

          bitmq::BasicProperties bp;
        bp.set_id(bitmq::UUIDHelper::uuid());
        bp.set_delivery_mode(bitmq::DeliveryMode::DURABLE);
        bp.set_routing_key("news.music.pop");
        channel->basicPubish("exchange1", &bp, "Hello World-" + std::to_string(i));
    }
    //6、关闭信道
    conn->closeChannel(channel);
    return 0;
}
